package com.skyable.common.common;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * @author GaoYuan
 * @date 2019/11/4 15:19
 * @desc 服务接口返回对象。
 *
 */
@Slf4j
@Data
public class ResponseResult<T> implements Serializable {

	/**
	 * 服务执行结果。
	 */
	private T result;
	/**
	 * 服务是否执行成功。
	 */
	private boolean success = true;
	/**
	 * 服务返回信息
	 */
	private String message;
	/**
	 * 返回码
	 */
	private Integer code;

	/**
	 * 成功默认方法
	 * @return
	 */
	public static ResponseResult success() {
		ResponseResult responseResult = new ResponseResult();
		responseResult.setCode(200);
		responseResult.setSuccess(true);
		return responseResult;
	}

	/**
	 * 成功默认方法
	 * @param result
	 * @return
	 */
	public static ResponseResult success(Object result) {
		ResponseResult responseResult = new ResponseResult();
		responseResult.setSuccess(true);
		responseResult.setCode(200);
		responseResult.setResult(result);
		return responseResult;
	}

	/**
	 * 成功默认方法
	 * @param result
	 * @return
	 */
	public static ResponseResult success(Integer code, Object result) {
		ResponseResult responseResult = new ResponseResult();
		responseResult.setSuccess(true);
		responseResult.setCode(code);
		responseResult.setResult(result);
		return responseResult;
	}

	/**
	 * 成功默认方法
	 * @param result
	 * @param message
	 * @return
	 */
	public static ResponseResult success(Integer code, Object result, String message) {
		ResponseResult responseResult = new ResponseResult();
		responseResult.setSuccess(true);
		responseResult.setCode(200);
		responseResult.setResult(result);
		responseResult.setMessage(message);
		return responseResult;
	}

	/**
	 * 失败默认方法
	 * @param errorCode
	 * @param errorDesc
	 * @return
	 */
	public static ResponseResult error(Integer errorCode, String errorDesc) {
		ResponseResult responseResult = new ResponseResult();
		responseResult.setSuccess(false);
		responseResult.setCode(errorCode);
		responseResult.setMessage(errorDesc);
		return responseResult;
	}

}
